﻿using Paperless.Entities;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Web;

namespace Paperless.Migrations
{
    internal sealed class Configuration : DbMigrationsConfiguration<PaperlessContext>
    {

        //Add-Migration name
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(PaperlessContext context)
        {
            context.Statuses.AddOrUpdate(x => x.Name, new Status()
                {
                    Name = "Start"
                }, new Status()
                {
                    Name = "Finish"
                }
            );

            context.SaveChanges();

            context.Locations.AddOrUpdate(x => x.Name, 
                new Location()
                {
                    Name = "location"
                },       
                new Location()
                {
                    Name = "location2"
                }
            );

            context.SaveChanges();

            var user = new User()
            {
                UserName = "user1",
                LocationId = 1,
                Email = "test@test.test",
                FirstName = "first",
                LastName = "last",
                PasswordHash = "AE8Ing///pQByPN67fR9SHHXTp1f9XC+Q5NjhmXHbcE1hVvObdthngRcpQSDiyy0VQ==",
                SecurityStamp = "17f6ccc3-e832-44f6-95cc-5d4bbddd98d1"
            };

            context.Users.AddOrUpdate(x => x.LastName, user);

            context.SaveChanges();

            context.Transactions.AddOrUpdate(x => x.Name,
                new Transaction()
                {
                    ListPrice = 200,
                    SellPrice = 300,
                    AcceptanceDate = DateTime.Now,
                    BuyerName = "buyer",
                    SellerName = "seller",
                    StatusId = context.Statuses.First().Id,
                    TotalCommission = 244,
                    TransactionNo = "transaction no",
                    CloseDate = DateTime.Now.AddDays(32),
                    CommissionSummary = "summary",
                    ExpiredDate = DateTime.Now.AddDays(2),
                    Name = "name",
                    LocationId = context.Locations.First().Id,
                    CreatedBy = user.Id,
                    CreatedDate = DateTime.Now,
                    MoreInfo = "more info",
                    OutsideListingAgent = "OutsideListingAgent",
                    OutsideSellingAgent = "OutsideSellingAgent"
                }
            );

            context.SaveChanges();
        }
    }
}